package co.fitstart.entity.user.bwh;

import java.text.ParseException;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.annotations.DynamicUpdate;

import com.demo2do.core.utils.DateFormatUtils;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.user.User;

/**
 * 
 * @author wangliwang
 *
 */
@Entity
@Table(name = "bwh_record")
@DynamicUpdate
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class BwhRecord {

    /** 主键 */
    @Id
    @GeneratedValue
    private Long id;
    
    /** 对应用户 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private User user;
    
    /** 对应课程 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private CourseRound courseRound;
    
    /** 胸围  - 保留两位小数 */
    private Float bust;
    
    /** 腰围 - 保留两位小数 */
    private Float waist;
    
    /** 臀围 - 保留两位小数 */
    private Float hips;
    
    /** 体重 - 保留两位小数 */
    private Float weight;
    
    /** 体脂率 保留小数点后一位*/
    private Float bodyFatRate;
    
    /** 骨骼肌 */
    private Float skeletalMuscle;
    
    /** 手臂围 */
    private Float arm;
    
    /** 腿围 */
    private Float thigh;
    
    /** 备注 */
    private String remark;
    
    /** 周 */
    private Integer week;
    
    /** 记录测试时间 */
    private String recordTime;

    /** 生成记录数据时间 */
    private Date createTime;
    
    /** 是否禁用 */
    @Column(name = "is_disabled")
    private Boolean disabled;
    
    /** 操作人 */
    private Long operator;
    
    /** 操作时间 */
    private Date operateTime;
    
    /**
     * The default constructor
     */
    public BwhRecord() {
        
    }
    
    public BwhRecord(CourseRound courseRound, int week) {
        this.user = courseRound.getStudent().getUser();
        this.courseRound = courseRound;
        this.week = week;
        this.recordTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        this.createTime = new Date();
        this.operator = courseRound.getCoach().getId();
        this.operateTime = new Date();
        this.disabled = false;
    }
    
    /**
     * 
     * @param courseRound
     * @param coach
     * @return
     */
    public BwhRecord initilization(CourseRound courseRound, Principal siteService) {
        this.user = courseRound.getStudent().getUser();
        this.courseRound = courseRound;
        this.recordTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        this.createTime = new Date();
        this.disabled = false;
        this.operator = siteService.getId();
        this.operateTime = new Date();
        return this;
    }
    
    /**
     * 
     * @param user
     * @param coach
     * @return
     */
    public BwhRecord initilization(User user, Principal coach) {
        this.user = user;
        this.recordTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        this.createTime = new Date();
        this.disabled = false;
        this.operator = coach.getId();
        this.operateTime = new Date();
        return this;
    }
    
    /**
     * 
     * @param courseRound
     * @return
     */
    public BwhRecord initilization(CourseRound courseRound) {
        this.user = courseRound.getStudent().getUser();
        this.courseRound = courseRound;
        this.recordTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        this.createTime = new Date();
        this.disabled = false;
        
        return this;
    }
    
    /**
     * edit
     * @param bwhRecord
     * @param coach
     * @return
     */
    public BwhRecord edit(BwhRecord bwhRecord, Long coach) {
        this.bust = bwhRecord.getBust();
        this.waist = bwhRecord.getWaist();
        this.hips = bwhRecord.getHips();
        this.weight = bwhRecord.getWeight();
        this.bodyFatRate = bwhRecord.getBodyFatRate();
        this.remark = bwhRecord.getRemark();
        this.operateTime = new Date();
        this.operator = coach;
        
        return this;
    }
    
    /**
     * 
     * @param weight
     * @param bodyFatRate
     * @param skeletalMuscle
     * @param Bust
     * @param arm
     * @param waist
     * @param hips
     * @param thigh
     * @return
     */
    public BwhRecord edit(Float weight, Float bodyFatRate, Float skeletalMuscle,
            Float bust, Float arm, Float waist, Float hips, Float thigh, Long coach) {
        this.weight = weight;
        this.bodyFatRate = bodyFatRate;
        this.skeletalMuscle = skeletalMuscle;
        this.bust = bust;
        this.arm = arm;
        this.waist = waist;
        this.hips = hips;
        this.thigh = thigh;
        this.operateTime = new Date();
        this.operator = coach;
        
        return this;
    }
    
    /**
     * The constructor using primary key
     */
    public BwhRecord(Long id) {
        this.id = id;
    }
    
    /**
     * 
     * @return
     * @throws ParseException 
     */
    public Date recordTimeToDate() throws ParseException {
        return DateUtils.parseDate(this.recordTime, "yyyy-MM-dd HH:mm:ss");
    }
    
    /**
     * 
     * @param operator
     * @return
     */
    public BwhRecord opeator(Long operator) {
        this.operator = operator;
        this.operateTime = new Date();
        return this;
    }
    
    /**
     * 
     * @param bust
     * @param waist
     * @param hips
     * @param operator
     * @return
     */
    public BwhRecord opeator(float bust, float waist, float hips, Long operator) {
        this.bust = bust;
        this.waist = waist;
        this.hips = hips;
        this.operator = operator;
        this.operateTime = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @return the courseRound
     */
    public CourseRound getCourseRound() {
        return courseRound;
    }

    /**
     * @return the bust
     */
    public Float getBust() {
        return bust;
    }

    /**
     * @return the waist
     */
    public Float getWaist() {
        return waist;
    }

    /**
     * @return the hips
     */
    public Float getHips() {
        return hips;
    }

    /**
     * @return the weight
     */
    public Float getWeight() {
        return weight;
    }

    /**
     * @return the bodyFatRate
     */
    public Float getBodyFatRate() {
        return bodyFatRate;
    }

    /**
     * @return the skeletalMuscle
     */
    public Float getSkeletalMuscle() {
        return skeletalMuscle;
    }

    /**
     * @return the arm
     */
    public Float getArm() {
        return arm;
    }

    /**
     * @return the thigh
     */
    public Float getThigh() {
        return thigh;
    }

    /**
     * @return the remark
     */
    public String getRemark() {
        return remark;
    }

    /**
     * @return the week
     */
    public Integer getWeek() {
        return week;
    }

    /**
     * @return the recordTime
     */
    public String getRecordTime() {
        return recordTime;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @return the operator
     */
    public Long getOperator() {
        return operator;
    }

    /**
     * @return the operateTime
     */
    public Date getOperateTime() {
        return operateTime;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @param courseRound the courseRound to set
     */
    public void setCourseRound(CourseRound courseRound) {
        this.courseRound = courseRound;
    }

    /**
     * @param bust the bust to set
     */
    public void setBust(Float bust) {
        this.bust = bust;
    }

    /**
     * @param waist the waist to set
     */
    public void setWaist(Float waist) {
        this.waist = waist;
    }

    /**
     * @param hips the hips to set
     */
    public void setHips(Float hips) {
        this.hips = hips;
    }

    /**
     * @param weight the weight to set
     */
    public void setWeight(Float weight) {
        this.weight = weight;
    }

    /**
     * @param bodyFatRate the bodyFatRate to set
     */
    public void setBodyFatRate(Float bodyFatRate) {
        this.bodyFatRate = bodyFatRate;
    }

    /**
     * @param skeletalMuscle the skeletalMuscle to set
     */
    public void setSkeletalMuscle(Float skeletalMuscle) {
        this.skeletalMuscle = skeletalMuscle;
    }

    /**
     * @param arm the arm to set
     */
    public void setArm(Float arm) {
        this.arm = arm;
    }

    /**
     * @param thigh the thigh to set
     */
    public void setThigh(Float thigh) {
        this.thigh = thigh;
    }

    /**
     * @param remark the remark to set
     */
    public void setRemark(String remark) {
        this.remark = remark;
    }

    /**
     * @param week the week to set
     */
    public void setWeek(Integer week) {
        this.week = week;
    }

    /**
     * @param recordTime the recordTime to set
     */
    public void setRecordTime(String recordTime) {
        this.recordTime = recordTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

    /**
     * @param operator the operator to set
     */
    public void setOperator(Long operator) {
        this.operator = operator;
    }

    /**
     * @param operateTime the operateTime to set
     */
    public void setOperateTime(Date operateTime) {
        this.operateTime = operateTime;
    }
}
